import * as service from "@/service";
import { IFood } from "./interface";
const food: IFood = {
  namespaced: true,
  state: {
    foods: [],
    list: [],
  },
  actions: {
    async getFoodList({ commit }) {
      const result = await service.fetchFoodList();

      const action = {
        type: "GETFOODLIST",
        payload: result?.data,
      };
      commit(action);
    },
    async getFooditem({ commit }, { cid, name }) {
      const result = await service.fetchFoodlist(cid, name);
      const action = {
        type: "GetFoodLisT",
        payload: result?.data?.content,
      };
      commit(action);
    },
  },
  mutations: {
    GETFOODLIST(state, action) {
      // const obj: any = {
      //   id: "",
      //   cid: "",
      //   name: "精选",
      //   banner: "",
      //   jump_url: "",
      //   url: "",
      //   icon: "",
      //   sub_class: [
      //     {
      //       api_id: "",
      //       icon: "",
      //       id: "",
      //       jump_url: "",
      //       name: "",
      //       original_id: "",
      //       s_type: 1,
      //     },
      //   ],
      // };
      // action.payload.unshift(obj);
      state.foods = action.payload;
    },
    GetFoodLisT(state, action) {
      state.list = action.payload;
    },
  },
};
export default food;
